package com.wealth.scsj.b_app.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.bean.OrderBean;
import com.wealth.scsj.b_app.bean.OrderSonBean;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单
 */

public class OrderAdapter extends BaseQuickAdapter<OrderBean, BaseViewHolder> {

    private Context mContext;
    private ArrayList<OrderSonBean>list;
    private OrderSonAdapter adapter;
    private boolean isOpen = false;


    public OrderAdapter(Context mContext,List data) {
        super(R.layout.item_order_layout, data);
        this.mContext =  mContext;
    }

    @Override
    protected void convert(final BaseViewHolder helper, OrderBean item) {

        helper.setText(R.id.id_tv, item.getOrderID());
        helper.setText(R.id.type_tv, item.getType());
        helper.setText(R.id.name_tv, item.getName());
        helper.setText(R.id.adress_tv, item.getAddress());
        helper.setText(R.id.kilo_tv, item.getKilo());

        helper.setText(R.id.money_tv3, item.getPrice1());
        helper.setText(R.id.money_tv1, item.getPrice2());
        helper.setText(R.id.money_tv2, item.getPrice3());
        helper.setText(R.id.money_tv3, item.getPrice4());

        helper.setText(R.id.orderid_tv, item.getOrdernum());
        helper.setText(R.id.ordertime_tv, item.getOrdertime());
        helper.setText(R.id.sendtime_tv, item.getSendtime());

        final LinearLayout up_ll = helper.getView(R.id.up_ll);
        final RelativeLayout top_ll = helper.getView(R.id.top_ll);

        RecyclerView goods_rv = helper.getView(R.id.goods_rv);
        goods_rv.setLayoutManager(new LinearLayoutManager(mContext));
        list = new ArrayList<>();
        for (int i=0;i<5;i++){
            list.add(new OrderSonBean("花生牛奶果汁","3","¥ 545"));
        }
        adapter = new OrderSonAdapter(list);
        goods_rv.setAdapter(adapter);

        helper.getView(R.id.colse_up_ll).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (isOpen == false){
                    isOpen = true;
                    helper.setVisible(R.id.tip_rl,true);
                    helper.setVisible(R.id.forsale_rl,true);
                    helper.setVisible(R.id.service_rl,true);
                    helper.setVisible(R.id.line3_tv,true);
                    helper.setVisible(R.id.react_rl,true);
                    helper.setVisible(R.id.line4_tv,true);
                    helper.setVisible(R.id.orderconfig_ll,true);
                    helper.setVisible(R.id.name_ll,true);
                    helper.setVisible(R.id.address_rl,true);
                }else {
                    isOpen =false;
                    helper.setVisible(R.id.tip_rl,false);
                    helper.setVisible(R.id.forsale_rl,false);
                    helper.setVisible(R.id.service_rl,false);
                    helper.setVisible(R.id.line3_tv,false);
                    helper.setVisible(R.id.react_rl,false);
                    helper.setVisible(R.id.line4_tv,false);
                    helper.setVisible(R.id.orderconfig_ll,false);
                    helper.setVisible(R.id.name_ll,false);
                    helper.setVisible(R.id.address_rl,false);
                    up_ll.scrollTo(0,top_ll.getBottom());

                }
            }
        });
    }
}
